package written;

import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

/**
 * 写个JAVA程序完成解析一个URL参数的值
 * 输入：
 * http://rongzi.1688.com?bill_no=2020100100222&product_code=CXB&tenant=TAOBAO
 * 输出：
 * 2020100100222
 * CXB
 * TAOBAO
 *
 * @author TANGYE
 * @date 2021-01-02 10:09
 **/
public class QuestionOne {

    public static void analysisUrl(String url) {
        if (null == url || "".equals(url)) {
            throw new RuntimeException("param url is empty");
        }
        if (url.indexOf("?") == -1) {
            throw new RuntimeException("url's rule is error, must contains '?'");
        }
        String[] str = url.split("\\?");
        String params = str[1];
        String[] paramArr = params.split("&");
//        System.out.println(Arrays.stream(paramArr).collect(Collectors.joining("\n")));
        for (String param : paramArr) {
            System.out.println(param.split("=")[1]);
        }
    }

    public static void main(String[] args) {
        String url = "http://rongzi.1688.com?bill_no=2020100100222&product_code=CXB&tenant=TAOBAO";
        analysisUrl(url);
    }
}
